<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.docman.domainmodel.*" %>
<%@page import="java.util.ArrayList"%>
<%@ page import="java.text.NumberFormat" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>DocMan Dosya Sayfası</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css">
	table.docInfo td p {font-size: 1.05em; font-weight: bold; color: #5481E3;}
	table.comment {width: 50%; border-collapse: collapse; border: 2px solid #5481E3 }
	table.comment td {width: 23%;}
	table.comment td p {font-size: 1.05em; font-weight: 300; color: black;}
</style>

<link rel="stylesheet" type="text/css" href="js/jRating/jRating.jquery.css" media="screen" />

<script type="text/javascript" src="js/jRating/jquery.js"></script>
<script type="text/javascript" src="js/jRating/jRating.jquery.js"></script>

<script src="js/jquery.validate.js" type="text/javascript"></script>


<script type="text/javascript">
  $(document).ready(function(){
    $(".rating").jRating({
	  length : 5, // nb of stars
	  decimalLength : 0, // number of decimal in the rate
	  canRateAgain : false,
	  rateMax :5,
	  step:true
	
    });
  });
  

</script>
<script type="text/javascript">
  $(document).ready(function(){
	    $(".rating2").jRating({
		  length : 5, // nb of stars
		  decimalLength : 0, // number of decimal in the rate
		  canRateAgain : false,
		  rateMax :5,
		  step:true
		
	    });
	  });
  </script>
<script type="text/javascript">

jQuery(function()
{
	jQuery("#comment").validate(
            {
                expression: "if (VAL) return true; else return false;",
                message: " <span style=\"color:red\">Yorum girmediniz.</span>"
            });
});
</script>
</head>
<body>

<div id="main_container">
	<div id="header">
			<div class="logo"><a href="index.jsp"><img src="img/top.png" border="0" alt="" title="" /></a></div>       
	</div>
        <div class="menu">
        	<ul>                                                                         
        		<li><a href="index.jsp">Anasayfa</a></li>
                <li><a href="profileServletpath">Profil</a></li>
                <li><a href="getTagServletpath?sId=0">Dosya Yükleme</a></li>
                <li><a href="getTagServletpath?sId=1">Ayrıntılı arama</a></li>
                <li><a href="contract.jsp">İletişim</a></li>
                <% if(session.getAttribute("currentSessionUser")!= null){ 
                 UserBean user = (UserBean)session.getAttribute("currentSessionUser");%>
                <li><a href="logout.jsp">Çıkış <span style="color: red;">(<span style="font-weight: bold;
                     text-decoration: underline"><%= user.getUserName() %></span>)</span></a></li>
                <% } else { %>
                <li><a href="getUniandDeptServletpath">Kaydol</a></li>
                <% } %>
        	</ul>
        </div>
        
    <div class="center_content">
    
        <% if(session.getAttribute("currentSessionUser")!= null){ 
        	UserBean user = (UserBean)(session.getAttribute("currentSessionUser"));
        	DocumentBean doc = (DocumentBean)request.getAttribute("document");
        	ArrayList<CommentBean> comments = (ArrayList<CommentBean>)request.getAttribute("comments");
        	String uploaderRating = request.getAttribute("uploaderRating").toString();%>           
			
			<table class="docInfo">
				<tr>
					<td><p>Dosya Başlığı:</p></td>
					<td><p><%= doc.getTitle()  %></p></td>
				</tr>
				<tr>
					<td><p>Dosya Adı:</p></td>
					<td><p><%= doc.getDocName()  %></p></td>
				</tr>
				<tr>
					<td><p>Dosya Kategorisi :</p></td>
					<td><p><%= doc.getTag()  %></p></td>
				</tr>
				<tr>
					<td><p>Yükleyen Kişi:</p></td>
					
					<td><p><%= doc.getUploader() %> (Rating: <%=uploaderRating.substring(0, 3) %>)</p></td>
					<td><div class="rating2" data-average="3" data-id="<%=doc.getUploader() %> " style="width: 2em; height: 1em; overflow: hidden; z-index: 1; position: relative; cursor: default;"></div></td>
				</tr>
				<tr>
					<td><p>Yüklenme Tarihi:</p></td>
					<td><p><%= doc.getUploadDate()  %></p></td>
				</tr>
				<tr>
					<td><p>Yorum:</p></td>
					<td><p><%= doc.getComment()  %></p></td>
				</tr>
				
				<tr>
					
					<td><p>Rating:</p></td>
					<td><p><%
					NumberFormat nf = NumberFormat.getInstance();
				    nf.setMaximumFractionDigits(1);
				 
					double d1= doc.getRating(), d2=doc.getRatingCount() ,result; 
					if(d1!=0 && d2!=0)
						result=d1/d2;
					else
						result =0;
					%>
					<%=nf.format(result) %>
					</p></td>
					<td><div class="rating" data-average="3" data-id="<%=doc.getDocId()%>" style="width: 2em; height: 1em; overflow: hidden; z-index: 1; position: relative; cursor: default;"></div></td>
				
				</tr>
				
				<tr>
				
					<td colspan="2"><center>
						<form action="downloadServletpath" method="post" >
							<input type="hidden" name="link" value="<%= doc.getDocName() %>" />
							<input class="button" type="submit" value="İNDİR" border="0" style="width:10em" />
						</form>
						</center></td>
				</tr>
			</table>
			
			<hr />
			
			<fieldset>
					<h2 style="color: #5481E3; text-decoration: underline">Yorum Ekle</h2>
			
					<form action="commentServletpath" method="post">
					<textarea rows="5" cols="50" name="comment" id="comment"></textarea>
					<input type="hidden" name="docId" value="<%= doc.getDocId() %>"/>
					<input type="hidden" name="commenter" value="<%= user.getUserName() %>" /><br />
					<input type="submit" name="submit" value="Ekle" class="button"/>
 				</form>
 			</fieldset>
 			
 			<hr />
 			<br />
 			<h2 style="text-align: center; color: #5481E3; text-decoration: underline">Yorumlar</h2>
 			<% for(int i=0;i<comments.size();i++){%>
 			<center><table class="comment" border="1">
 				<tr>
 					<td><p><%= comments.get(i).getCommenter() %></p></td>
 					<td><p><%= comments.get(i).getCommentDate() %></p></td>
 				</tr>
 				<tr>
 					<td colspan="2" rowspan="2"><p><%= comments.get(i).getComment() %></p></td>
 				</tr>
 			</table></center>
 			<br />
			<% } %>
		<% }else { %>
		
			<p style="font-size: 1.5em; text-align: center;color:red">Lütfen <a href="index.jsp">Anasayfa</a>'dan giriş yapınız.  </p>	
			<p style="font-size: 1.5em; text-align: center;color:red">Veya menüden Kaydol butonuna tıklayıp sitemize üye olabilirsiniz. </p>
		
		<% } %> 
    </div>
         
</div>

</body>
</html>